package cn.javass.dp.builder.demo2;

import javax.swing.*;

//1、定义产品  产品由哪些部件组成？
public class PanelProduct extends JPanel {
    JButton button;
    JLabel label;
    JTextField textField;

    public static void main(String[] args) {
        Builder a = new ConcreteBuilderOne();
        Builder b = new ConcreteBuilderTwo();
        Director d = new Director(b);
        JPanel panel = d.construct();
        JFrame frameOne = new JFrame();
        frameOne.add(panel);
        frameOne.setBounds(12, 12, 200, 120);
        frameOne.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frameOne.setVisible(true);

    }
}

interface Builder {
    void bulidButton();
    void buildLabel();
    void buildTextField();
    JPanel getPanel();
}

class Director {
    Builder builder;
    public Director(Builder builder) {
        this.builder = builder;
    }
    public JPanel construct() {
        builder.bulidButton();
        builder.buildTextField();
        builder.buildLabel();
        return builder.getPanel();
    }
}
